﻿#include "core/Simulator.h"

#include <core/CPU.h>
#include <core/Enum.h>
#include <utils/ThreadPool.h>
#include <utils/AsyncManager.h>

#define TAG "Simulator"

Simulator* Simulator::singleton = nullptr;

Simulator::~Simulator()
{
    if (_cpu != nullptr) {
        delete _cpu;
        _cpu = nullptr;
    }
}

Simulator* Simulator::getInstance()
{
    if (Simulator::singleton == nullptr) {
        singleton = new Simulator();
    }
    return singleton;
}

CPU* Simulator::init()
{
    _arch = CPUArch::Arm64;
    _cpu = new CPU();
    //初始化虚拟CPU资源
    _cpu->init(_arch);
    //初始化虚拟外设资源
    AsyncManager::getInstance()->init();
    //初始化本地资源
    //ThreadPool::getInstance()->start();
    //协程调度器提交到线程开始调度
    //ThreadPool::getInstance()->submitTask(AsyncManager::SchedulerNext, AsyncManager::getInstance());
    //暂时加这个
    //std::this_thread::sleep_for(std::chrono::seconds(3)); // 延时1秒
    return _cpu;
}

int Simulator::mainLoopShouldExit()
{
    return 0;
}

